import axios from "axios";

const instance = axios.create({
  baseURL: "http://localhost:3000",
  timeout: 10000,
});

// 电影相关接口
export const movieAPI = {
  // 获取分页电影列表
  getMovies: ({ page, pageSize }) =>
    instance
      .get("/movies", {
        params: {
          // _page: page,
          // _limit: pageSize,
          _order: "asc",
        },
      })
      .then((response) => {
        const total = response.data.length;
        console.log("总数量:", total);
        console.log(response.data);

        return {
          list: response.data,
          total: total,
        };
      }),

  // 新增电影
  createMovie: (data) => instance.post("/movies", data),

  // 更新电影
  updateMovie: (id, data) => instance.put(`/movies/${id}`, data),

  // 删除电影
  deleteMovie: (id) => instance.delete(`/movies/${id}`),
};

// 新增分类接口
export const categoryAPI = {
  getCategories: () => instance.get("/categories"),
};
